const path = require('path')
const merge = require('webpack-merge')
const BaseModules = require('../BaseModules')
const { resolve, exists } = require('../../helper')

const userBabelrc = exists(BaseModules.appConf.babelrc, true) || {}
const userPostcssrc = exists(BaseModules.appConf.postcssrc, true) || {}
const babelrc = merge({}, require(path.join(__dirname, '../../babel.config')), userBabelrc)
const postcssrc = merge({}, require(path.join(__dirname, '../../postcss.config')), userPostcssrc)


module.exports = {
	cssLoader: [
		{ loader: 'css-loader', options: { sourceMap: false } },
		{ loader: 'postcss-loader', options: postcssrc }
	],
	otherLoader: [
		{
			test: /\.js$/,
			use: [{loader: 'babel-loader', options: babelrc }],
			include: [resolve(BaseModules.appConf.src), resolve('node_modules/@ynet')],
			exclude: /node_modules\/(?!@ynet\b)/
		},
		{ test: /\.vue$/, use: [{loader: 'vue-loader'}] },
		{
			test: /\.(png|jpe?g|gif)$/,
			use({resourceQuery}){
				return resourceQuery === '?base64' ? 
				{loader:'url-loader',options:{limit:100000}} : 
				{loader: 'file-loader',options: {name: 'img/[name].[contenthash:7].[ext]'}}
			}
		},
		{
			test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
			use: [{loader:'file-loader',options:{name: 'font/[name].[contenthash:7].[ext]'}}]
		},
		{
			test: /\.(svg)(\?.*)?$/,
			use: [{loader:'file-loader',options:{name: 'svg/[name].[contenthash:7].[ext]'}}]
		}
	]
}